package cn.oscar.controller;

import cn.oscar.service.CommentService;
import commonUtils.entities.Comment;
import commonUtils.entities.Restful;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 根据博客id查询评论
     * @param id 传入的博客id
     * @return 返回该博客对应的所有评论信息
     */
    @GetMapping("/{id}")
    public Restful<List<Comment>> selectCommentByBlogId(@PathVariable Long id){
        return commentService.selectCommentByBlogId(id);
    }

    /**
     * 新增评论
     * @param comment 新增的评论信息
     * @return 返回新增结果
     */
    @PutMapping
    public Restful<String> addComments(@RequestBody Comment comment){
        return commentService.addComments(comment);
    }

    /**
     * 删除评论
     * @param comment 删除的评论
     * @return 返回删除结果
     */
    @DeleteMapping
    public Restful<String> deleteComment(@RequestBody Comment comment){
        return commentService.deleteComment(comment);
    }

}
